<template>
    <view class="page bg-fff">
        <block v-for="(item,index) in list" :key="index">
            <image class="itemImg" :lazy-load="true" :src="item" mode="widthFix"></image>
        </block>
        <share-btn :display="scrollAnimate"></share-btn>
    </view>
</template>

<script>
    import { mapState, mapActions } from 'pinia';
    import { useUserInfoStore, useConfigStore } from '@/store/index';
    import { policyImagesById } from '@/common/api/menus';
    // import { dispatchClient } from '@/common/api-adviser';
    export default {
        data() {
            return {
                typeId: '',
                shareTitle: '',
                shareImage: '',
                scrollAnimate: false,
                list: [],
                productId: '',
                share: false,
            }
        },
        computed:{
            ...mapState(useUserInfoStore, ['userInfo']),
            ...mapState(useConfigStore, ['puid'])
        },
        onShareAppMessage(res) {
            return {
                title: this.shareTitle,
                imageUrl: this.shareImage,
                path: `/pages/tools/policy/pages?typeId=${this.typeId}&puid=${this.userInfo.id}&share=true`,
            }
        },
        //#ifdef MP-WEIXIN
        onShareTimeline() {
            return {
                title: this.shareTitle,
                imageUrl: this.shareImage,
                query: `typeId=${this.typeId}&puid=${this.userInfo.id}&share=true`
            }
        },
        //#endif
        onLoad(options) {
            const that = this;
            let { typeId='', productId='', puid='', share=false } = options;
            this.typeId = typeId?typeId : '';
            this.productId = productId?productId:'';
            this.share = JSON.parse(share);
            if(puid) {
                this.setPuid(puid)
            }
            uni.$check_and_login(function () {
                that.init();
            })
        },
        
        onPageScroll() {
            const that = this;
            that.scrollAnimate = true;
            this.$u.debounce(function() {
                that.scrollAnimate = false;
            }, 500);
        },
        methods: {
            ...mapActions(useConfigStore, ['setPuid']),

            //初始化
            async init() {
                let imagesRes = await policyImagesById(this.typeId);
                if(imagesRes.status === 0) {
                    let { title, share_image, image_list } = imagesRes.detail;
                    this.shareTitle = title;
                    this.shareImage = share_image;
                    this.list = image_list;
                    uni.setNavigationBarTitle({
                        title: title?title:'政策'
                    });
                }
                // if(this.puid) {
                    // dispatchClient({
                    //     share: this.share,
                    //     puid: this.puid,
                    //     pid: this.productId
                    // });
                // }
            }
        }
    }
</script>

<style lang="scss" scoped>
    .page{
        font-size: 0;
        min-height: 100vh;
        .itemImg{
            width: 100%;
            display: block;
        }
    }
</style>
